/**
 * 
 */
package com.anxin.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;

import com.anxin.common.utils.CookiesManager;
import com.anxin.constants.SessionConstants;

/**
 * 
 * @author sj
 *
 */
public class BaseController {

	@Autowired
	protected MessageSource messageSource;

	public Long getUserId(HttpServletRequest request) {

		Object sessionObj = request.getSession().getAttribute(SessionConstants.SESSION_USERID);
		// Long userId = 1l;
		Long userId = null;
		if (sessionObj != null) {
			return (Long) sessionObj;
		}

		String userIdString = CookiesManager.getCookie(request, SessionConstants.COOKIE_USERID);
		if (StringUtils.isBlank(userIdString)) {
			userIdString = request.getParameter("userId");
		}

		userIdString = request.getParameter("userId");

		if (StringUtils.isBlank(userIdString)) {
			return null;
		}
		userId = Long.valueOf(userIdString);
		return userId;

	}

}
